<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>账号登录</span>
      </div>
      <div>
        <el-form ref="form" :model="login" label-width="80px">
          <el-form-item label="账号" class="top1">
            <el-input v-model="login.tel" placeholder="请输入账号"></el-input>
          </el-form-item>
          <el-form-item label="密码" class="top1">
            <el-input v-model="login.password" placeholder="请输入密码" show-password></el-input>
          </el-form-item>
          <el-form-item class="top2">
            <el-checkbox-group v-model="checkList">
              <el-checkbox label="记住我"></el-checkbox>
              <el-checkbox label="员工登录"></el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <el-form-item class="top2">
            <el-button type="primary" @click="tologin" style="width: 140px">登录</el-button>
            <el-button @click="goAdmin" style="width: 140px">首页</el-button>
          </el-form-item>
          <el-form-item class="top2">
            <el-link type="info" @click="register">注册用户</el-link>
            &emsp;&emsp;&emsp;&emsp;
            <el-link type="info" @click="findPwd">找回密码</el-link>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      checkList: [],
      login: {
        tel: "qqq",
        password: "qqq",
      },
    };
  },
  methods: {
    findPwd() {
      this.$router.push("/FindUserPwd");
    },
    register() {
       this.$router.push("/UserRegister");
      
    },
    goAdmin() {
      this.$router.push("/UserAdmin");
    },
    tologin() {
      //用户登录
      if (this.checkList.indexOf("员工登录") != -1) {
        var emp = { empUacc: this.login.tel, empPassword: this.login.password };
        this.$axios.post("emp/login", this.$qs.stringify(emp)).then((res) => {
          if (res.data.code == 200) {
            sessionStorage.setItem("emp", JSON.stringify(res.data.data.emp));
            sessionStorage.setItem("list", JSON.stringify(res.data.data.list));
            sessionStorage.setItem('authorization', res.data.data.token);
            this.$router.push("/EmpAdmin");
          } else {
            this.$router.push("/Login");
          }
        });

      } else {
       this.$axios.post("user/login", this.$qs.stringify(this.login)).then((res) => {
         
          if (res.data.code == 200) {
            sessionStorage.setItem("user", JSON.stringify(res.data.data.user));
           sessionStorage.setItem('authorization', res.data.data.token);
            this.$router.push("/UserAdmin");
          } else {
            this.$router.push("/Login");
          }
        });
      }
    },
  },
};
</script>
<style>
.top2 {
  margin-left: -20%;
}

.top1 {
  margin-left: -40px;
}

.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}

.box-card {
  margin-top: 10%;
  margin-left: 35%;
  width: 28%;
}
</style>